package com.jxl.springboot.game.web;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回前端数据模型
 *
 * @author 江雪林
 * @create 2021-03-19
 */
public class WebResult {
    private Integer code;//响应状态码
    private String message;//响应消息
    private Map<String, Object> map;//响应数据

    public WebResult() {
        this.map = new HashMap<String, Object>();
    }

    public WebResult(Integer code, String message) {
        this.code = code;
        this.message = message;
        this.map = new HashMap<String, Object>();
    }

    public WebResult(Integer code) {
        this.code = code;
        this.map = new HashMap<String, Object>();
    }

    public WebResult(Integer code, Map<String, Object> map) {
        this.code = code;
        this.map = map;
    }

    public WebResult(Integer code, String message, Map<String, Object> map) {
        this.code = code;
        this.message = message;
        this.map = map;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    /**
     * 以 key-value 存储值
     *
     * @param key    key值
     * @param object value值
     * @return
     */
    public WebResult put(String key, Object object) {
        this.map.put(key, object);
        return this;
    }

    /**
     * 以 key-value 存储值
     * 用 result取值
     *
     * @param object value值
     * @return
     */
    public WebResult put(Object object) {
        this.map.put("datas", object);
        return this;
    }
}
